package com.cdu.async;

import com.cdu.mapper.SysLogMapper;
import com.cdu.pojo.SysLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * projectName : app3_spring2ibatis
 * className: LogAsync
 * description: TODO 类描述
 *
 * @author : git.jas0nch
 * date: 2022-03-28
 */

@Component
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class LogAsync {

    @Autowired
    private SysLogMapper sysLogMapper;

    /**
     * @param
     * @return : void
     * @description : 异步添加日志，减少等待时间。
     * @author : git.jas0nch
     * date : 2022/3/28
     **/
    @Async

    public void addOperationLog(SysLog sysLog) {
        // ################################
        log.info("正在异步执行日志操作...");
        // ################################
        sysLog.setCreator("supperAdmin");
        sysLog.setCreateTime(new Date());
        //
        int insert = sysLogMapper.insert(sysLog);
    }
}
